//package com.ruoyi.oar.controller.app;
//
//import cn.hutool.core.bean.BeanUtil;
//import com.alibaba.fastjson.JSONObject;
//import com.ruoyi.common.core.controller.BaseController;
//import com.ruoyi.common.core.domain.AjaxResult;
//import com.ruoyi.common.core.domain.Response;
//import com.ruoyi.common.core.domain.entity.SysUser;
//import com.ruoyi.common.core.redis.RedisCache;
//import com.ruoyi.common.mongo.MongoUtils;
//import com.ruoyi.common.utils.SecurityUtils;
//import com.ruoyi.common.utils.sign.Base64;
//import com.ruoyi.oar.api.util.CarHttpUtil;
//import com.ruoyi.oar.controller.vo.PeopleCheckVO;
//import com.ruoyi.oar.controller.vo.SysUserVO;
//import com.ruoyi.oar.domain.dto.OarCheckInRecordDTO;
//import com.ruoyi.oar.service.OarCheckInRecordService;
//import com.ruoyi.system.service.ISysUserService;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import io.swagger.annotations.ApiParam;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.validation.annotation.Validated;
//import org.springframework.web.bind.annotation.*;
//
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * 登录验证
// *
// * @author ruoyi
// */
//@Api(tags = "APP小程序用户信息")
//@RestController
//@RequestMapping("/app")
//public class AppUserInfoController extends BaseController {
//    @Autowired
//    private ISysUserService userService;
//    @Autowired
//    private RedisCache redisCache;
//    @Autowired
//    private OarCheckInRecordService oarCheckInRecordService;
//
//    /**
//     * 获取用户信息
//     *
//     * @return 用户信息
//     */
//    @ApiOperation("小程序用户信息")
//    @GetMapping("/getInfo")
//    public Response<SysUserVO> getInfo() {
//        SysUser user = SecurityUtils.getLoginUser().getUser();
//        return Response.success(BeanUtil.toBean(user, SysUserVO.class));
//    }
//
//    /**
//     * 人证核验
//     *
//     * @return 人证核验
//     */
//    @ApiOperation("人证核验")
//    @PostMapping("/people-check")
//    public AjaxResult peopleCheck(@Validated @RequestBody @ApiParam("人证核验参数") PeopleCheckVO peopleCheck) {
//        logger.debug("人证核验,peopleCheck={}", JSONObject.toJSONString(peopleCheck));
//        //String sonwKey= RedisConstants.REDIS_CARD_VERIFI_SONW_KEY +peopleCheck.getSonwId();
//        //if (!redisCache.exists(sonwKey)) {
//        //    throw new ServiceException("二维码已失效，请重新扫码填写");
//        //}
//        //String key = RedisConstants.REDIS_PEOPLE_CHECK_KEY + peopleCheck.getGmsfzhm();
//        //if (redisCache.exists(key)) {
//        //    throw new ServiceException("核验中，请勿重复操作");
//        //}
//        //redisCache.setCacheObject(key, "核验中", 20, TimeUnit.SECONDS);
//        OarCheckInRecordDTO oarCheckInRecordDTO = new OarCheckInRecordDTO();
//        try {
//            //参数
//            Map<String, Object> map = new HashMap<>();
//            map.put("xm", peopleCheck.getXm());
//            map.put("gmsfhm", peopleCheck.getGmsfzhm());
//            //压缩32K
//            byte[] bytes = PicUtils.compressPicForScale(Base64.decode(peopleCheck.getXp()), 32);
//            String imgBase64Str=Base64.encode(bytes);
//            map.put("xp",imgBase64Str);
//            oarCheckInRecordDTO.setId(peopleCheck.getRecordId());
//            //三要素核验
//            Integer isConsistent = CarHttpUtil.checkPortraitcomparison(map);
//            if(isConsistent==1){//人脸核验通过
//                oarCheckInRecordDTO.setFaceVerifiState(1);
//            }else{//人脸核验不通过
//                oarCheckInRecordDTO.setFaceVerifiState(2);
//            }
//            String imgUrl = MongoUtils.addFile(imgBase64Str);
//            oarCheckInRecordDTO.setFaceImageUrl(imgUrl);
//            oarCheckInRecordService.updateOarCheckInRecord(oarCheckInRecordDTO);
//
//        } finally {
//            //redisCache.deleteObject(key);
//        }
//        if(2==oarCheckInRecordDTO.getFaceVerifiState()){
//            return AjaxResult.success(2);
//        }
//        //redisCache.deleteObject(sonwKey);
//        return AjaxResult.success(1);
//    }
//
//}
